<?PHP

import('izz.web.WebAppContext');



/**

 * iforum application context

 * 

 * @package  iforum.web

 * @author   iCer <iCer@justdn.com>

 * @version  $Id: iForumWebAppContext.php,v 1.2 2005/04/04 10:41:11 icer Exp $

 */

class iForumWebAppContext extends WebAppContext

{

	var $_registry = null;
	var $_currentUser;

	

	function &getRegistry()

	{

		if($this->_registry == null)

		{

			import('izz.system.Registry');

			$this->_registry = Singleton::instance('Registry');

			$this->_registry->initialize('web.config.php');

			return $this->_registry;

		}

		else 

		{

			return $this->_registry;

		}		

	}

	

	function &getDaoFactory()

	{

		import('iforum.dao.DAOFactory');

		

		$registry = &$this->getRegistry();

		

		$param = $registry->getRegistryValues();

		$factoryType = $param['db_setting']['db_type'];

		

		return DAOFactory::getDAOFactory($factoryType);

	}

	

	function &getCurrentUser()
	{
		$request = $this->getRequest();
		$userid = $request->getCookie('user_id');
		$passhash = $request->getCookie('pass_hash');
		
		if (!isset($this->_currentUser))
		{
			$daofactory = $this->getDaoFactory();
			$dao = &$daofactory->getUserDao();
			
			if ($userid>1 && strlen($passhash)>0)
			{
				$user = $dao->getUser($userid);
				if ($passhash == $user['password'])
				{
					$this->_currentUser = $user;
				}
				else 
				{
					$this->_currentUser = $dao->getGuest();
				}
				return $this->_currentUser;	
			}
			else 
			{
				$this->_currentUser = $dao->getGuest();
				return $this->_currentUser;	
			}
		}
		else 
		{
			return $this->_currentUser;	
		}
	}

	

	function &getServiceLocator()
	{}

}



?>